home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3413 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.8 KB

  1. Path: news.bridge.net!news
  2. From: David Byrden <100101.2547@compuserve.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Vector of abstract classes using STL
  5. Date: 23 Jan 1996 18:59:26 GMT
  6. Organization: self-employed
  7. Message-ID: <4e3b6e$uee@news.bridge.net>
  8. References: <3103699A.79F8@ce.kth.se> <3103DF74.2C71@cs.rpi.edu>
  9. NNTP-Posting-Host: ppp-mia2-71.bridge.net
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.1N (Windows; I; 16bit)
  14.  
  15.  
  16.  
  17. >>>> > I'm new to STL and have a question about vectors.
  18.  
  19. >> You must either store shape references (Shape&) or shape pointers
  20. >> (Shape*) in the container
  21.  
  22.  
  23. I refer you to the draft standard, section 23.1.2
  24.  
  25. "The  type of objects stored in these components must meet the 
  26. requirements of CopyConstructible types  (_lib.copyconstructible_),  and 
  27. the additional requirements of Assignable types."
  28.  
  29. It is impossible to assign a reference (that is, to point it at another 
  30. object). Therefore, it is impossible to have a container of references.
  31.  
  32. Even a beginning C++ programmer should be aware that there are no arrays 
  33. of references, and should therefore be suspicious of the concept of 
  34. keeping them in a container.
  35.  
  36.  
  37. >> Or, you may add the following to your Shape header:
  38. >>     void destroy (Shape** ptr) { delete *ptr; }
  39.  
  40. Interference with the internal workings of the STL is not recommeneded. In 
  41. particular, this technique is dangerous because the global destroy() 
  42. function is a workaround made necessary by the lack of template member 
  43. functions in current compilers. When these become available, the global 
  44. destroy() function will be removed from STL implementations, and this code 
  45. will no longer work.
  46.  
  47.  
  48.  
  49.                            David Byrden
  50.  
  51.  
  52.             ||  C++ training for professional programmers  ||
  53.             ||    My opinions ARE those of my employer     ||
  54.  
  55.  
  56.  
  57.